package com.company;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.ArrayList;

public class stusys {
    private JButton 查询Button;
    private JPanel panel1;
    private JButton 维护Button;
    private JTable table1;
    private DefaultTableModel table2;
    private Object[][] data;
    private String[] total={"学号","姓名","性别","系别","寝室","班级","年级"};
    private static String driver = "oracle.jdbc.driver.OracleDriver";
    private static String url = "jdbc:oracle:thin:@localhost:1521:XE";
    private static String user="hr";
    private static String password="123456";
    public static final int k = 7;
    public stusys() {
        JFrame stus = new JFrame("学生管理");
        stus.setSize(400, 400);
        stus.add(panel1);
        stus.setLocation(400,250);
        stus.setVisible(true);
        查询Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            ZSGC zs=new ZSGC();
                try {
                    Connection conn = DriverManager.getConnection(url, user, password);//连接数据库
                    PreparedStatement pst = conn.prepareStatement("select * from student");//准备执行SQL语句
                    ResultSet rs = pst.executeQuery();
                    int sample = 0;
                    while (rs.next()) {
                        sample++;
                    }
                    String[][] a=zs.chazhao();
                    for(int i=0;i<sample;i++)
                        table2.addRow(a[i]);
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }

            }
        });
        维护Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new weihu();
            }
        });
    }
    public static void main(String[] args) {
        stusys st=new stusys();
    }
    private void createUIComponents() {
        // TODO: place custom component creation code here
        data=null;
        table2=new DefaultTableModel(data,total);
        table1 = new JTable(table2);
    }
}
